﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Albon.Model;
using Commonlib;


namespace DAL
{
    public class PayMentDAL
    {
        //PayMent

        /// <summary>
        /// 添加/修改付款信息
        /// </summary>
        public bool addPayMent(PayMent payment)
        {
            SqlParameter[] parameters = {
					new SqlParameter("@invoiceNo", payment.invoiceNo),
					new SqlParameter("@payMoney", payment.payMoney),
					new SqlParameter("@receiver", payment.receiver),
					new SqlParameter("@remark",payment.remark)};
            return SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnectionString, CommandType.StoredProcedure, "p_paymentadd", parameters) == 1;
        }

        /// <summary>
        /// 获取同一Invoice的付款金额总和
        /// </summary>
        public DataTable allPayMent(string  invoiceNo)
        {
            string cmdstr = "select * from PayMent where invoiceNo="+invoiceNo;
            return SqlHelper.ExecuteDataSet(SqlHelper.SqlConnectionString,CommandType.Text,cmdstr,null).Tables[0];
        }

        public bool deletePayMent(string paymentID)
        {
            string cmdstr = "delete from PayMent where ID="+paymentID;
            return SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnectionString, CommandType.Text, cmdstr, null)>0;
        }
    }
}
